/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yoga.algo.polygon;

import java.awt.Polygon;
import java.util.Random;
import yoga.probability.Probablistics;

/**
 *
 * @author Yogev Montekyo
 */
public class PolygonGenerator
{
    public static Polygon getKNormalPolygon(int numberOfCoordinates)
    {

        Polygon polygon = new Polygon();

        for (int i = 0; i < numberOfCoordinates; i++)
        {
            int x = (int) (200 + 140 * Math.cos(i * 2 * Math.PI / numberOfCoordinates));
            int y = (int) (200 + 140 * Math.sin(i * 2 * Math.PI / numberOfCoordinates));
            polygon.addPoint(x, y);
        }

        return polygon;
    }

    public static Polygon getPolygonWithNoise(Polygon polygon, int randomness)
    {
        int numberOfCoordinates = polygon.npoints;
        Polygon newPolygon = new Polygon();
        for (int i = 0; i < numberOfCoordinates; i++)
        {            
            int x = polygon.xpoints[i] + Probablistics.getRandomInt(randomness * 2) - randomness;
            int y = polygon.ypoints[i] + Probablistics.getRandomInt(randomness * 2) - randomness;
            newPolygon.addPoint(x, y);                    
        }
        
        return newPolygon;
    }

    public static Polygon getRandomPolygon(int numOfCoordinates, int width, int height)
    {

        Polygon polygon = new Polygon();

        int padding = 20;

        for (int i = 0; i < numOfCoordinates; i++)
        {
            int x = Probablistics.getRandomInt(width) + padding;
            int y = Probablistics.getRandomInt(height) + padding;
            polygon.addPoint(x, y);
        }
        return polygon;
    }
}
